package net.kehuilai.handler;

import com.alibaba.fastjson.JSON;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import net.kehuilai.model.BaseMessage;

/**
 * Created by genghz on 16/12/6.
 */
public class MessageEncoderHandler extends MessageToByteEncoder<BaseMessage> {
    @Override
    protected void encode(ChannelHandlerContext cxt, BaseMessage baseMessage, ByteBuf byteBuf) throws Exception {
        String msg = JSON.toJSONString(baseMessage);
        byteBuf.writeBytes(msg.getBytes());
    }
}
